package lanou.autohome.collection;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

import cn.bmob.v3.BmobUser;
import lanou.autohome.R;
import lanou.autohome.basetool.BaseActivity;
import lanou.autohome.basetool.DBTool;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.my.MyBemoUser;

/**
 * Created by dllo on 16/9/2.
 * 收藏
 */
public class CollectionActivity extends BaseActivity{

    private ImageView back;
    private ListView listView;
    private CollectionAdapter collectionAdapter;

    @Override
    protected int setLayout() {
        return R.layout.activity_collection;
    }

    @Override
    protected void intiView() {
        back = bindView(R.id.imageview_collection_back);
        listView = bindView(R.id.listview_collection);
        collectionAdapter = new CollectionAdapter(getApplicationContext());
        back.setOnClickListener(this);
    }

    @Override
    protected void intiData() {
        BmobUser bmobUser = BmobUser.getCurrentUser(BmobUser.class);
        Log.d("CollectionActivity", "bmobUser:" + bmobUser);
            DBTool dbTool = DBTool.getInstance();
            dbTool.queryUesr("users = ?", bmobUser.getUsername(), new DBTool.QueryListener() {
                @Override
                public void onQueryComplete(ArrayList<CollectionLocalBean> localBeen) {
                    if(localBeen != null) {
                        collectionAdapter.setCollectionLocalBeen(localBeen);
                        Log.d("CollectionActivity", "localBeen:" + localBeen);
                        listView.setAdapter(collectionAdapter);
                    }else {
                        Toast.makeText(CollectionActivity.this, "您还没有收藏哦", Toast.LENGTH_SHORT).show();
                    }
                }
            });
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.imageview_collection_back:
                finish();
                break;
        }
    }
}
